{% block sw_promotion_discount_component %}
<mt-card
    class="sw-promotion-discount-component"
    position-identifier="sw-promotion-discount-component"
    :title="$tc('sw-promotion.detail.main.discounts.card')"
>
    <sw-context-button class="sw-promotion-discount-component__context-button">
        {% block sw_promotion_detail_discounts_item_context_button_delete %}
        <sw-context-menu-item
            v-tooltip="{
                message: $tc('sw-privileges.tooltip.warning'),
                disabled: acl.can('promotion.editor'),
                showOnDisabledElements: true
            }"
            variant="danger"
            class="sw-promotion-context-item__delete-action"
            :disabled="isEditingDisabled"
            @click="onShowDeleteModal"
        >
            {{ $tc('sw-promotion.detail.main.discounts.buttonDeleteDiscount') }}
        </sw-context-menu-item>
        {% endblock %}
    </sw-context-button>

    <sw-container
        columns="1fr 1fr"
        gap="0px 30px"
    >
        {% block sw_promotion_discount_component_scope %}
        <mt-select
            ref="selectFieldScope"
            v-model="discount.scope"
            required
            validation="required"
            :label="$tc('sw-promotion.detail.main.discounts.labelScope')"
            :disabled="isEditingDisabled"
            :is-loading="isLoading"
            :options="fieldScopeOptions"
            @update:model-value="onDiscountScopeChanged"
        />
        {% endblock %}

        {% block sw_promotion_discount_condition_consider_product_rules_field %}
        <template v-if="displayAdvancedRuleOption">

            <mt-switch
                v-model="discount.considerAdvancedRules"
                bordered
                :label="$tc('sw-promotion.detail.main.discounts.flagProductScopeLabel')"
                :disabled="isEditingDisabled"
            />
        </template>
        {% endblock %}
    </sw-container>

    {% block sw_promotion_discount_condition_rules_form %}
    <template v-if="!shippingScope && discount.considerAdvancedRules === true">
        <div v-if="!isSetGroup">
            <sw-promotion-v2-rule-select
                v-model:collection="discount.discountRules"
                class="sw-promotion-discount-component__select-discount-rules"
                :local-mode="discount.isNew()"
                :criteria="ruleFilter"
                :label="$tc('sw-promotion.detail.main.discounts.labelRules')"
                :placeholder="$tc('sw-promotion.detail.main.discounts.placeholder')"
                :disabled="isEditingDisabled"
                :restricted-rules="restrictedRules"
                :restriction-snippet="promotionDiscountSnippet"
                rule-aware-group-key="promotionDiscounts"
            />
        </div>

        <sw-container
            columns="1fr 1fr"
            gap="0px 30px"
        >
            {% block sw_promotion_cart_condition_setgroup_filter_apply_field %}
            <mt-select
                v-if="!isSet"
                v-model="discount.applierKey"
                :label="$tc('sw-promotion.detail.main.discounts.labelApplyCount')"
                :disabled="isEditingDisabled"
                :options="applyCountOptions"
            />
            {% endblock %}
            {% block sw_promotion_cart_condition_setgroup_filter_usage_field %}
            <mt-select
                v-if="isMaxUsageVisible"
                v-model="discount.usageKey"
                :label="$tc('sw-promotion.detail.main.discounts.labelMaxCount')"
                :disabled="isEditingDisabled"
                :options="maxCountOptions"
            />
            {% endblock %}

        </sw-container>

        <template v-if="discount.applierKey!=='ALL'">
            <sw-container
                columns="1fr 1fr"
                gap="0px 30px"
            >
                {% block sw_promotion_cart_condition_setgroup_filter_sorting_field %}
                <mt-select
                    v-model="discount.sorterKey"
                    :label="$tc('sw-promotion.detail.main.discounts.labelSorting')"
                    :disabled="isEditingDisabled"
                    :options="sorterOptions"
                />
                {% endblock %}
                {% block sw_promotion_cart_condition_setgroup_filter_picker_field %}
                <mt-select
                    v-if="isPickingModeVisible"
                    v-model="discount.pickerKey"
                    :label="$tc('sw-promotion.detail.main.discounts.labelPicking')"
                    :disabled="isEditingDisabled"
                    :options="pickerOptions"
                />
                {% endblock %}
            </sw-container>
        </template>

    </template>
    {% endblock %}

    <sw-container
        columns="1fr 1fr"
        gap="0px 30px"
    >
        {% block sw_promotion_discount_component_type %}
        <mt-select
            v-model="discount.type"
            class="sw-promotion-discount-component__type-select"
            :label="$tc('sw-promotion.detail.main.discounts.labelType')"
            :disabled="isEditingDisabled"
            :options="discountTypeOptions"
            @update:model-value="onDiscountTypeChanged"
        />
        {% endblock %}
        {% block sw_promotion_discount_component_value %}
        <mt-number-field
            class="sw-promotion-discount-component__discount-value"
            validation="required"
            required
            :model-value="discount.value"
            :label="$tc('sw-promotion.detail.main.discounts.labelValue')"
            :placeholder="$tc('sw-promotion.detail.main.discounts.placeholderValue')"
            :disabled="isEditingDisabled"
            @update:model-value="onDiscountValueChanged"
        >
            <template #suffix>
                {{ valueSuffix }}
            </template>
        </mt-number-field>
        {% endblock %}
    </sw-container>

    {% block sw_promotion_discount_max_value %}
    <sw-container
        v-if="showMaxValueSettings"
        :key="1"
        columns="1fr 1fr"
        justify="end"
    >
        {% block sw_promotion_discount_max_value_field %}
        <mt-number-field
            v-model="discount.maxValue"
            :label="$tc('sw-promotion.detail.main.discounts.labelMaxValue')"
            :help-text="$tc('sw-promotion.detail.main.discounts.helpTextMaxValueAdvancedPrices')"
            :disabled="isEditingDisabled"
            @update:model-value="onMaxValueChanged"
        >
            <template #suffix>
                {{ maxValueSuffix }}
            </template>
        </mt-number-field>
        {% endblock %}
        {% block sw_promotion_discount_max_value_advanced_prices %}
        <a
            v-if="showMaxValueAdvancedPrices"
            class="sw-card__quick-link advanced-prices"
            role="button"
            tabindex="0"
            @click="onClickAdvancedPrices"
            @keydown.enter="onClickAdvancedPrices"
        >
            {{ $tc('sw-promotion.detail.main.discounts.linkAdvancedPrices') }}
            <mt-icon
                name="regular-long-arrow-right"
                size="16px"
            />
        </a>
        {% endblock %}
    </sw-container>
    {% endblock %}

    {% block sw_promotion_discount_advanced_prices_link %}
    <sw-container
        v-if="showAbsoluteAdvancedPricesSettings"
        :key="2"
        columns="1fr"
        justify="end"
    >
        <a
            class="sw-card__quick-link advanced-prices"
            role="button"
            tabindex="0"
            @click="onClickAdvancedPrices"
            @keydown.enter="onClickAdvancedPrices"
        >
            {{ $tc('sw-promotion.detail.main.discounts.linkAdvancedPrices') }}
            <mt-icon
                name="regular-long-arrow-right"
                size="16px"
            />
        </a>
    </sw-container>
    {% endblock %}

    {% block sw_promotion_discount_advanced_prices_modal %}
    <sw-modal
        v-if="displayAdvancedPrices"
        :title="$tc('sw-promotion.detail.main.discounts.pricesModal.advancedPricesHeader')"
        class="sw-promotion-discount-form__advanced-prices-modal"
        @modal-close="onCloseAdvancedPricesModal"
    >

        <sw-one-to-many-grid
            :collection="discount.promotionDiscountPrices"
            :local-mode="true"
            :columns="currencyPriceColumns"
            :show-selection="false"
            :is-loading="isLoading"
            :show-actions="!isEditingDisabled"
        >

            <template #column-currency.translated.name="{ item }">
                <p>{{ item.currency.translated.name }}</p>
            </template>

            <template #column-price="{ item }">
                <mt-number-field
                    v-model="item.price"
                    type="text"
                    size="small"
                    :disabled="isEditingDisabled"
                >
                    <template #suffix>
                        {{ item.currency.symbol }}
                    </template>
                </mt-number-field>
            </template>
        </sw-one-to-many-grid>

        <template #modal-footer>
            <mt-button
                variant="primary"
                size="small"
                @click="onCloseAdvancedPricesModal"
            >
                {{ $tc('sw-promotion.detail.main.discounts.pricesModal.closeModal') }}
            </mt-button>
        </template>
    </sw-modal>
    {% endblock %}

    {% block sw_promotion_detail_discounts_modal_delete %}
    <sw-modal
        v-if="showDeleteModal"
        variant="small"
        :title="$tc('sw-promotion.detail.main.discounts.delete.confirmTitle')"
        class="sw-promotion-detail-discounts-modal"
        @modal-close="onCloseDeleteModal"
    >
        {% block sw_promotion_detail_discounts_modal_delete_text %}
        <p>
            {{ $tc('sw-promotion.detail.main.discounts.delete.confirmText') }}
        </p>
        {% endblock %}

        {% block sw_promotion_detail_discounts_modal_delete_footer %}
        <template #modal-footer>
            {% block sw_promotion_detail_discounts_modal_delete_action_cancel %}
            <mt-button
                size="small"
                variant="secondary"
                @click="onCloseDeleteModal"
            >
                {{ $tc('global.default.cancel') }}
            </mt-button>
            {% endblock %}

            {% block sw_promotion_detail_discounts_modal_delete_action_delete %}
            <mt-button
                size="small"
                variant="critical"
                class="sw-promotion-discount-delete-button"
                @click="onConfirmDelete"
            >
                {{ $tc('sw-promotion.detail.main.discounts.delete.buttonDelete') }}
            </mt-button>
            {% endblock %}
        </template>
        {% endblock %}
    </sw-modal>
    {% endblock %}
</mt-card>
{% endblock %}
